package com.market.product.server.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.market.cart.common.domain.CartInfo;
import com.market.common.security.utils.SecurityUtils;
import com.market.product.common.response.ProductInfoResponse;
import com.market.system.common.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import com.market.common.log.annotation.Log;
import com.market.common.log.enums.BusinessType;
import com.market.common.security.annotation.RequiresPermissions;
import com.market.product.common.domain.ProductInfo;
import com.market.product.server.service.IProductInfoService;
import com.market.common.core.web.controller.BaseController;
import com.market.common.core.utils.poi.ExcelUtil;
import com.market.common.core.web.page.TableDataInfo;
import com.market.common.core.domain.Result;
import org.springframework.web.multipart.MultipartFile;

/**
 * 商品信息Controller
 *
 * @author market
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/product")
public class ProductInfoController extends BaseController
{
    @Autowired
    private IProductInfoService productInfoService;

    /**
     * 查询商品信息列表
     */
    @RequiresPermissions("product:product:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(ProductInfo productInfo)
    {
        startPage();


        List<ProductInfo> list = productInfoService.selectProductInfoList(productInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品信息列表
     */
    @RequiresPermissions("product:product:export")
    @Log(title = "商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductInfo productInfo)
    {
        List<ProductInfo> list = productInfoService.selectProductInfoList(productInfo);
        ExcelUtil<ProductInfo> util = new ExcelUtil<ProductInfo>(ProductInfo.class);
        util.exportExcel(response, list, "商品信息数据");
    }



    /**
     * 获取商品详细信息
     */
    @RequiresPermissions("product:product:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(productInfoService.selectProductInfoById(id));
    }

    /**
     * 新增商品信息
     */
    @RequiresPermissions("product:product:add")
    @Log(title = "商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody ProductInfo productInfo)
    {
        return toAjax(productInfoService.insertProductInfo(productInfo));
    }

    /**
     * 修改商品信息
     */
    @RequiresPermissions("product:product:edit")
    @Log(title = "商品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody ProductInfo productInfo)
    {
        return toAjax(productInfoService.updateProductInfo(productInfo));
    }

    /**
     * 批量删除商品信息
     */
    @RequiresPermissions("product:product:removes")
    @Log(title = "商品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result removes(@PathVariable Long[] ids)
    {
        return toAjax(productInfoService.deleteProductInfoByIds(ids));
    }

    /**
     * 删除商品信息
     */
    @RequiresPermissions("product:product:del")
    @Log(title = "商品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Long id)
    {
        return toAjax(productInfoService.deleteProductInfoById(id));
    }




    /**
     * 商品信息添加购物车
     */
    @RequiresPermissions("product:product:ProductInformationAddSCart")
    @Log(title = "商品信息", businessType = BusinessType.INSERT)
    @PostMapping("/{id}")
    public Result ProductInformationAddSCart(@PathVariable Long id)
    {
        Result result=productInfoService.ProductInformationAddSCart(id);
        return Result.success(result);
    }



























}
